7000 // Intel 8253/8254/82C54 Programmable Interval Timer (PIT).
7001 // Only used on uniprocessors;
7002 // SMP machines use the local APIC timer.
7003 
7004 #include "types.h"
7005 #include "defs.h"
7006 #include "traps.h"
7007 #include "x86.h"
7008 
7009 #define IO_TIMER1       0x040           // 8253 Timer #1
7010 
7011 // Frequency of all three count-down timers;
7012 // (TIMER_FREQ/freq) is the appropriate count
7013 // to generate a frequency of freq Hz.
7014 
7015 #define TIMER_FREQ      1193182
7016 #define TIMER_DIV(x)    ((TIMER_FREQ+(x)/2)/(x))
7017 
7018 #define TIMER_MODE      (IO_TIMER1 + 3) // timer mode port
7019 #define TIMER_SEL0      0x00    // select counter 0
7020 #define TIMER_RATEGEN   0x04    // mode 2, rate generator
7021 #define TIMER_16BIT     0x30    // r/w counter 16 bits, LSB first
7022 
7023 void
7024 timerinit(void)
7025 {
7026   // Interrupt 100 times/sec.
7027   outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
7028   outb(IO_TIMER1, TIMER_DIV(100) % 256);
7029   outb(IO_TIMER1, TIMER_DIV(100) / 256);
7030   picenable(IRQ_TIMER);
7031 }
7032 
7033 
7034 
7035 
7036 
7037 
7038 
7039 
7040 
7041 
7042 
7043 
7044 
7045 
7046 
7047 
7048 
7049 
